package com.ruoyi.wms.controller.partolStore;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.idempotent.annotation.RepeatSubmit;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.web.core.BaseController;
import com.ruoyi.common.mybatis.core.page.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.excel.utils.ExcelUtil;
import com.ruoyi.wms.domain.vo.inspectionRecordsVo;
import com.ruoyi.wms.domain.bo.partolStore.inspectionRecordsBo;
import com.ruoyi.wms.service.inspectionRecordsService;
import com.ruoyi.common.mybatis.core.page.TableDataInfo;

/**
 * 巡检记录
 *
 * @author xhr
 * @date 2024-12-03
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/wms/inspection_records")
public class inspectionRecordsController extends BaseController {

    private final inspectionRecordsService inspectionRecordsService;

    /**
     * 查询巡检记录列表
     */
    @SaCheckPermission("wms:inspection_records:list")
    @GetMapping("/list")
    public TableDataInfo<inspectionRecordsVo> list(inspectionRecordsBo bo, PageQuery pageQuery) {
        return inspectionRecordsService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出巡检记录列表
     */
    @SaCheckPermission("wms:inspection_records:export")
    @Log(title = "巡检记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(inspectionRecordsBo bo, HttpServletResponse response) {
        List<inspectionRecordsVo> list = inspectionRecordsService.queryList(bo);
        ExcelUtil.exportExcel(list, "巡检记录", inspectionRecordsVo.class, response);
    }

    /**
     * 获取巡检记录详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("wms:inspection_records:query")
    @GetMapping("/{id}")
    public R<inspectionRecordsVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(inspectionRecordsService.queryById(id));
    }

    /**
     * 新增巡检记录
     */
    @SaCheckPermission("wms:inspection_records:add")
    @Log(title = "巡检记录", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody inspectionRecordsBo bo) {
        inspectionRecordsService.insertByBo(bo);
        return R.ok();
    }

    /**
     * 修改巡检记录
     */
    @SaCheckPermission("wms:inspection_records:edit")
    @Log(title = "巡检记录", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody inspectionRecordsBo bo) {
        inspectionRecordsService.updateByBo(bo);
        return R.ok();
    }

    /**
     * 删除巡检记录
     *
     * @param ids 主键串
     */
    @SaCheckPermission("wms:inspection_records:remove")
    @Log(title = "巡检记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        inspectionRecordsService.deleteByIds(List.of(ids));
        return R.ok();
    }
}
